"""前台路由"""
from fastapi import APIRouter, Depends

from app.dependencies import Dependencies
from app.schemas.codeSchemas import SendCodeRequest, SendCodeResponse
from app.schemas.userSchemas import UserRegisterRequest, UserRegisterResponse
from app.servers.frontend.codeServers.codeLogic import CodeLogic
from app.servers.frontend.userServers.userLogic import UserLogic

frontendRouter = APIRouter(tags=["前台接口"])


@frontendRouter.post("/", response_model=UserRegisterResponse,tags=["user 管理接口"])
async def register_user(req: UserRegisterRequest, user: UserLogic = Depends(), logger=Depends(Dependencies.get_logger)):
    """
    注册用户
    :param user:
    :param logger:
    :return:
    """
    logger.info("注册用户")
    re = user.register()
    return UserRegisterResponse(
        id=1,
        username="q",
        email=re,
    )


@frontendRouter.post("/send_code",response_model=SendCodeResponse)
async def send_code(req: SendCodeRequest, code: CodeLogic = Depends(), logger=Depends(Dependencies.get_logger)):
    """
    发送验证码
    """
    await code.send_code(req,logger)
    return SendCodeResponse(
        message="发送成功"
    )
